using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;

using Janus.Windows.TimeLine;
namespace Janus.NorthwindDemo2007
{
	public partial class OrdersTimelineView
	{

		protected override void OnFolderViewChanged()
		{

			TimeLineLayout layout = this.Timeline.FindLayout(this.FolderView.LayoutName);
			this.Timeline.CurrentLayout = layout;
			layout.SetDataBinding(this.DataSource, "Orders");

			this.SetFieldsValueList();

			this.Timeline.FirstDate = DateTime.Today;
		}
		private void SetFieldsValueList()
		{
			DataView view = new DataView(NorthwindApp.NorthwindApplication.GetShippersList());
			this.Timeline.Fields["ShipVia"].HasValueList = true;
			this.Timeline.Fields["ShipVia"].ValueList.PopulateValueList(view, "ShipperID", "CompanyName", "SmallIcon", Color.Magenta, new Size(16, 16));

			view = new DataView(NorthwindApp.NorthwindApplication.GetCountriesTable());
			this.Timeline.Fields["ShipCountry"].HasValueList = true;
			this.Timeline.Fields["ShipCountry"].ValueList.PopulateValueList(view, "Country", "Country", "Flag", Color.Magenta, new Size(19, 13));

			this.Timeline.Fields["Paid"].HasValueList = true;
			this.Timeline.Fields["Paid"].ItemsImage = true;

			TimeLineValueListItemCollection valueList = this.Timeline.Fields["Paid"].ValueList;
			valueList.Add(new TimeLineValueListItem(true, "Paid", 3));
			valueList.Add(new TimeLineValueListItem(false, "UnPaid", 4));

			view = new DataView(NorthwindApp.NorthwindApplication.GetEmployeeList());
			this.Timeline.Fields["EmployeeID"].HasValueList = true;
			this.Timeline.Fields["EmployeeID"].ValueList.PopulateValueList(view, "EmployeeID", "Name", "Photo", Color.Magenta, new Size(16, 16));

			view = new DataView(NorthwindApp.NorthwindApplication.GetCustomersList());
			this.Timeline.Fields["CustomerID"].HasValueList = true;
			this.Timeline.Fields["CustomerID"].ValueList.PopulateValueList(view, "CustomerID", "CompanyName");

			this.Timeline.Refetch();
		}


		private void Timeline_ItemRead(object sender, Janus.Windows.TimeLine.ItemEventArgs e)
		{
			if (! System.Convert.IsDBNull(e.Item.GetValue("OrderDate")))
			{
				System.DateTime od = System.Convert.ToDateTime(e.Item.GetValue("OrderDate"));
				e.Item.ToolTipText = "Order Date: " + od.ToString("d");

			}

		}

		public override void Edit()
		{
			foreach (ITimeLineObject item in this.Timeline.SelectedItems)
			{
				if (item.Item != null)
				{
					OrderDataForm orderDialog = new OrderDataForm();
					orderDialog.Edit(((DataRowView)item.Item.DataRow).Row);
				}
			}
		}


	}

} //end of root namespace